﻿using DryIoc;
using Prism.Commands;
using Prism.Events;
using Prism.Ioc;
using Prism.Mvvm;
using Prism.Regions;
using StarryEdge.Core;
using StarryEdge.Core.Enums;
using StarryEdge.Core.Manager;
using StarryEdge.Core.Parameter;
using StarryEdge.Core.Tool;
using StarryEdge.Model;
using StarryEdge.Views;
using StarryEdge.WPF.Lang;
using StarryEdge.WPF.Models;
using System;
using System.Security.Principal;
using System.Windows;

namespace StarryEdge.ViewModels
{
    public class MainWindowViewModel : BindableBase
    {
        private object _userWindow;

        public object UserWindow
        {
            get { return _userWindow; }
            set { SetProperty(ref _userWindow, value); }
        }

        private IContainerProvider _containerProvider;

        public MainWindowViewModel(IContainerProvider containerProvider, IEventAggregator eventAggregator)
        {
            _containerProvider = containerProvider;
            var regionViewRegistry = containerProvider.Resolve<IRegionViewRegistry>();
            regionViewRegistry.RegisterViewWithRegion("MenuContentRegion", typeof(Views.EnumTree));
            regionViewRegistry.RegisterViewWithRegion("ResectionContentRegion", typeof(Views.StatusBar));
            regionViewRegistry.RegisterViewWithRegion("UserLoginContentRegion", typeof(Views.UserLogin));
            _ = _containerProvider.Resolve<IDeviceInfoManage>();
            eventAggregator.GetEvent<MessageEvent>().Subscribe(sender => {
                if (sender != null && sender.Data.ContainsKey("View"))
                {
                    UserWindow = sender.Data["View"];
                }
            }, arg => arg.Code == 200);
            if (KeyboardHook.Start())
            {
                containerProvider.Resolve<IStarryEdgeLog>().LogRun(LangManager.Instance.ToolTip["HookSuccess"], LogLevel.Success);
            }
            else
            {
                containerProvider.Resolve<IDialogHost>().DialogShow(LangManager.Instance.ToolTip["HookError"], LogLevel.Error, hostDialog: PopUpTypes.Global);
            }
            //containerProvider.Resolve<IDialogHost>().DialogShow("当前不是管理员运行软件，关闭软件后，设置兼容性为管理员，在运行软件!!!", LogLevel.Error, hostDialog: PopUpTypes.Global);
        }
    }
}
